﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public class SuppliersBLL
    {
        DigitalWorldDataContext db = new DigitalWorldDataContext();
        /// <summary>
        /// Hàm lấy danh sách nhà cung cấp sắp xếp giảm dần
        /// </summary>
        /// <returns></returns>
        public List<supplier> getSupplier() {
            return db.suppliers.OrderByDescending(s => s.supplierid).ToList();
        }
        /// <summary>
        /// Hàm thêm mới 1 nhà cung cấp
        /// </summary>
        /// <param name="sup"></param>
        public void Suppliers_Insert(supplier sup) {
            db.sp_Suppliers_Insert(sup.companyname, sup.contactname, sup.contacttitle, sup.address, sup.city, sup.postalcode, sup.country, sup.phone, sup.homepage);
            db.SubmitChanges();
        }
        /// <summary>
        /// Hàm cập nhật 1 nhà cung cấp
        /// </summary>
        /// <param name="sup">Lớp nhà cung cấp</param>
        public void Suppliers_Update(supplier sup) {
            db.sp_Suppliers_Update(sup.supplierid, sup.companyname, sup.contactname, sup.contacttitle, sup.address, sup.city, sup.postalcode, sup.country, sup.phone, sup.homepage, sup.status);
            db.SubmitChanges();
        }
        /// <summary>
        /// Hàm xoá 1 nhà cung cấp
        /// </summary>
        /// <param name="sup">Lớp nhà cung cấp</param>
        public void Suppliers_Delete(int supplierid) {
            db.sp_Suppliers_Delete(supplierid);
            db.SubmitChanges();
        }
    }
}
